package com.ruoyi.project.system.notification.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.notification.domain.PlatformNotification;
import com.ruoyi.project.system.notification.service.IPlatformNotificationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 平台通知Controller
 * 
 * @author LCL
 * @date 2021-10-08
 */
@Controller
@RequestMapping("/system/notification")
public class PlatformNotificationController extends BaseController
{
    private String prefix = "system/notification";

    @Autowired
    private IPlatformNotificationService platformNotificationService;

    @RequiresPermissions("system:notification:view")
    @GetMapping()
    public String notification()
    {
        return prefix + "/notification";
    }

    /**
     * 查询平台通知列表
     */
    @RequiresPermissions("system:notification:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlatformNotification platformNotification)
    {
        startPage();
        List<PlatformNotification> list = platformNotificationService.selectPlatformNotificationList(platformNotification);
        return getDataTable(list);
    }

    /**
     * 导出平台通知列表
     */
    @RequiresPermissions("system:notification:export")
    @Log(title = "平台通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlatformNotification platformNotification)
    {
        List<PlatformNotification> list = platformNotificationService.selectPlatformNotificationList(platformNotification);
        ExcelUtil<PlatformNotification> util = new ExcelUtil<PlatformNotification>(PlatformNotification.class);
        return util.exportExcel(list, "notification");
    }

    /**
     * 新增平台通知
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存平台通知
     */
    @RequiresPermissions("system:notification:add")
    @Log(title = "平台通知", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlatformNotification platformNotification)
    {
        return toAjax(platformNotificationService.insertPlatformNotification(platformNotification));
    }

    /**
     * 修改平台通知
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PlatformNotification platformNotification = platformNotificationService.selectPlatformNotificationById(id);
        mmap.put("platformNotification", platformNotification);
        return prefix + "/edit";
    }

    /**
     * 修改保存平台通知
     */
    @RequiresPermissions("system:notification:edit")
    @Log(title = "平台通知", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlatformNotification platformNotification)
    {
        return toAjax(platformNotificationService.updatePlatformNotification(platformNotification));
    }

    /**
     * 删除平台通知
     */
    @RequiresPermissions("system:notification:remove")
    @Log(title = "平台通知", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(platformNotificationService.deletePlatformNotificationByIds(ids));
    }
}
